package eirkdbd.lab1.log.model;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import eirkdbd.lab1.obj.Function;

public class SubConditionsModel implements TableModel<Function> {

	private static SubConditionsModel model = new SubConditionsModel();
	
	private Map<String, Function> functions;
	
	private SubConditionsModel() {
		functions = new HashMap<String, Function>();
	}
	
	public static SubConditionsModel getInstance() {
		return model;
	}
	
	public Iterator<Function> getModelObjects() {
		return functions.values().iterator();
	}
	
	public void clear() {
		functions.clear();
	}
	
	public void add(Function obj) {
		if(obj != null) {
			if(functions.isEmpty()) {
				obj.setJoin(null);
			} else {
				Function pers = functions.get(obj.getStatisticName());
				if(pers != null && pers.getJoin() == null) {
					obj.setJoin(null);
				}
			}
			functions.put(obj.getStatisticName(), obj);
		}
	}
}
